﻿#region Legal notice
/*
 * This file is part of EPPLib.
 * Copyright 2010, 2011 
 * Gianluca Esposito (info@gianlucaesposito.it)
 * ----------------------------------------------------------------------------
 * EPPLib is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 * 
 * EPPLib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with Nome-Programma; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net;
using System.IO;

namespace EPPWebMVC.Controllers
{
    public class ConsoleController : BaseController
    {
        [Authorize]
        public ActionResult Index()
        {
            SetBaseViewData();
            return View();
        }
        [Authorize]
        [ValidateInput(false)]
        [HttpPost]
        public ActionResult Index(FormCollection data)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("https://pub-test.nic.it"));
            request.Method = "POST";
            request.ContentType = "text/xml";
            if (!string.IsNullOrEmpty(data["request"]))
            {
                TempData["__REQUEST"] = data["request"];
                StreamWriter sw = new StreamWriter(request.GetRequestStream());
                sw.Write(data["request"]);
                sw.Close();
            }
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader sr = new StreamReader(response.GetResponseStream());
            string responseData = sr.ReadToEnd();
            sr.Close();
            response.Close();
            TempData["__RESPONSE"] = responseData;

            SetBaseViewData();
            return View();
        }
    }
}
